const express = require('express')
const router = express.Router()
const foodModel = require('../db/model/foodModel')

/**
 * @api {post} /food/add 添加菜品
 * @apiName /food/add
 * @apiGroup User
 *
 * @apiParam {String} name 菜品名称.
 * @apiParam {String} price 价格.
 * @apiParam {String} desc 验证码.
 * @apiParam {String} typename 用户名.
 * @apiParam {Number} typeid 用户密码.
 * @apiParam {String} img 验证码
 *
 * @apiSuccess {String} err 状态码 1成功，-1失败
 * @apiSuccess {String} msg  消息
 */
router.post('/add', (req, res) => {
    // let data = {
    //     name: '火山飘雪',
    //     price: '9999',
    //     desc: '超好吃',
    //     typename: '凉菜',
    //     typeid: 1,
    //     img: 'https://img20.360buyimg.com/mobilecms/s700x700_jfs/t17893/287/405450848/113084/186cc838/5a72cf86Nc0bdfcb3.jpg!q70.jpg'
    // }
    let { name, price, desc, typename, typeid, img } = res.body
    foodModel.insertMany({ name, price, desc, typename, typeid, img })
        .then((data) => {
            res.send({ err: 0, msg: '添加成功' })
        })
        .catch((err) => {
            res.send({ err: 0, msg: '添加失败' })
        })


})

module.exports = router

